package com.flower.core_service.controller;


import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.flower.core_service.object.entity.AuthMenu;
import com.flower.core_service.service.AuthMenuService;
import com.common.baseModel.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 菜单权限 前端控制器
 * </p>
 *
 * @author flower
 * @since 2022-03-29
 */
@RestController
@RequestMapping("/coreService/system/menu")
public class AuthMenuController {

    @Autowired
    AuthMenuService authMenuService;

    @GetMapping("/getAllMenu")
    public JsonResult<List<AuthMenu>> getAllMenu(){
        List<AuthMenu> allMenu = authMenuService.getAllMenu();
        return JsonResult.create(allMenu);
    }

    @PostMapping("/updateIcon")
    public JsonResult<Object> updateIcon(String id, String icon){
        authMenuService.updateIcon(id,icon);
        return JsonResult.isOk();

    }

    @PostMapping("/saveMenu")
    public JsonResult<Object> saveMenu(@RequestBody AuthMenu menu)
    {
        authMenuService.save(menu);
        return JsonResult.isOk();
    }

    @PostMapping("/removeMenu/{id}")
    public JsonResult<Object> removeMenu(@PathVariable(name = "id") String id)
    {
        authMenuService.removeMenu(id);
        return JsonResult.isOk();
    }

    @PostMapping("/updateMenu")
    public JsonResult<Object> updateMenu(@RequestBody AuthMenu menu){
        UpdateWrapper<AuthMenu> wrapper= new UpdateWrapper();
        wrapper.eq("id",menu.getId());
        authMenuService.update(menu,wrapper);
        return JsonResult.isOk();
    }

}

